package com.oauth.authserver.controller.publicapi;

import java.util.ArrayList;
import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.oauth.authserver.domain.User;

@RestController
/*@RequestMapping("/public/api")*/
public class UserApi {

	@GetMapping("/users")
	@PreAuthorize("hasAuthority('ROLE_USER')")
	public ModelAndView list(Model model) {
		List<User> list = new ArrayList<>();
		list.add(new User("jangz", 23));
		list.add(new User("Zychaowill", 23));
		model.addAttribute("title", "User Management");
		model.addAttribute("userList", list);
		return new ModelAndView("users/list", "userModel", model);
	}
}
